<template>
  <div>
    <!-- 卡片视图 -->

    <el-card>
      <div style="margin-bottom: 20px">《{{ filmName }}》</div>
      <el-table :data="evaList" :border="true" stripe>
        <el-table-column type="index" :resizable="false"></el-table-column>
        <el-table-column prop="comment" label="评论内容"></el-table-column>
        <el-table-column
          prop="score"
          label="评分"
          :resizable="false"
        ></el-table-column>
        <el-table-column
          prop="memberName"
          label="评论人"
          :resizable="false"
        ></el-table-column>
        <el-table-column
          prop="evaDate"
          label="评论时间"
          :resizable="false"
        ></el-table-column>
        <el-table-column label="操作">
          <template v-slot="scope">
            <el-button
              type="danger"
              size="mini"
              icon="el-icon-delete"
              @click="removeEvaById(scope.row.evaId)"
              >删除</el-button
            >
          </template>
        </el-table-column>
      </el-table>
    </el-card>
  </div>
</template>

<script>
export default {
  data() {
    return {
      evaList: [],
      filmName: "",
    };
  },
  methods: {
    async getEvaList() {
      const { data: res } = await this.$http.get(
        "common/evaluation/getListByFilm",
        { params: { filmId: this.$route.query.id } }
      );
      console.log(res);
      if (res.code != 200) {
        return this.$message.error(res.message);
      } else {
        this.evaList = res.data;
      }
    },
    async removeEvaById(id) {
      const res = await this.$confirm("永久删除，是否继续？", "提示", {
        confirmButtonText: "确定",
        cancelButtonText: "取消",
        type: "warning",
      }).catch((err) => err); //点取消会报错，捕获
      if (res != "confirm") {
        return this.$message.info("已取消删除");
      }
      const { data: result } = await this.$http.delete(
        "common//evaluation/removeEvaById",
        { params: { id: id } }
      );
      if (result.code != 200) {
        return this.$message.error(result.message);
      } else {
        this.getEvaList();
      }
    },
  },
  created() {
    this.getEvaList();
    this.filmName = this.$route.query.filmName;
  },
};
</script>

<style lang="less" scoped>
.el-dropdown-menu {
  width: 206.7px;
}
</style>